<?php

namespace app\taglib\fox;
use app\common\model\Basic;
use app\common\model\Column;
use app\common\model\VariateField;
use think\facade\Db;

/**
 * 基本
 */
class TagBasic extends TagBase
{
    /**
     * 查询数据
     */
    public function getList($param)
    {
        $visit_lang = $this->getLang();
        $siteInfo = "095fKQBlEPn8haWYOWZEqLGUryknDTchSrG+O6fiRmqdRagaqmK2ZErZXa15oYyG9V4qRxYMtw";
        if($visit_lang != "cn"){
            $siteInfo = "55587lthDGRaURkuFx7jiIjLqSHQail0DTGu5Zf1eT2rkCoo2LXgc6ftS/qYL8RYOy9u+qSenYgQ";
        }
        $siteInfo = dataD($siteInfo);
        $field = $param['field'];
        $add = $param['add'];
        $basics = Basic::where('lang', $visit_lang)->limit(1)->select();
        if(sizeof($basics) == 1){
            $basic = $basics[0];
            //查询字段变量状态
            if($field == "logo"){//网站LOGO
                echo $basic['logo_url'];
                return false;
            }elseif($field == "icon"){//URL图标
                echo $basic['url_icon_url'];
                return false;
            }elseif ($field == "aq"){
                $val = '<a class="foxcms-aq" href="https://beian.miit.gov.cn/" target="_blank">'.$basic->$field.'</a>'.'<a style="margin-left: 10px;" href ="//www.foxcms.cn" target="_blank">'.$siteInfo.'</a>';
                if($add == 1){
                    $val = "<a class='foxcms-aq' href='https://beian.miit.gov.cn/' target='_blank'>".$basic->$field."</a>";
                }
                echo $val;
                return false;
            }elseif ($field == "copyright"){
                $val = $basic->$field.'<a style="margin-left: 10px;" href ="//www.foxcms.cn" target="_blank">'.$siteInfo.'</a>';
                if($add == 1){
                    $val = $basic->$field;
                }
                echo $val;
                return false;
            }elseif($field == "url"){//URL图标
                $baseurl = request()->domain();//基本路径
                echo $baseurl;
                return false;
            }elseif ($field == "police_aq"){//公安备案号
                if(empty($basic->$field)){
                    echo "";
                    return false;
                }
                preg_match("/\d{10,}/", $basic->$field, $matches);
                $recordcode = $matches[0];
                $val = '<a style="display: flex; align-items: center" class="foxcms-police-aq" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode='.$recordcode.'" target="_blank">
                            <img style="height: 1.2em" src="" alt="">
                            <span style="margin-left: 6px">'.$basic->$field.'</span>
                        </a>';
                echo $val;
                return false;
            }
            $vf = VariateField::where("name","{$field}")->where("group", "basic")->find();


            if($vf){
                if($vf["dtype"] == "media"){
                    $mediaArr = json_decode($basic[$field]);
                    if(sizeof($mediaArr) > 0){
                        $media = $mediaArr[0];
                        echo $media->url;
                        return false;
                    }
                }
            }
            echo $basic[$field];
            return false;
        }else{
            echo "";
            return false;
        }

    }

}